﻿picShare.service('registerSvc', function (httpRequestSvc, pageLocatorSvc, userDataSvc) {
    var registerUser = function (userName, password) {

        //TODO Validate Input Fields

        var calculateHash = CryptoJS.SHA1(password);
        var hash = calculateHash.toString();

        var user = {
            userName: userName,
            authCode: hash,
        };

        httpRequestSvc.postJson(httpRequestSvc.httpRootUserUrl + "register", user).done(
            function (data) {
                userDataSvc.putUserInfo(data.id, data.userName, data.sessionKey, data.albumNames);
                pageLocatorSvc.goTo("/albums");
            }, function (err) {
                alert(err);
            });
    };

    return {
        registerUser: registerUser
    };
});